package com.czy.workflow.core.validator;

import com.czy.workflow.core.context.FlowContext;
import com.czy.workflow.core.model.FlowNode;
import com.czy.workflow.core.model.OperationType;
import com.czy.workflow.core.model.TaskInfo;

public class FlowDefaultValidator implements FlowValidator{

    @Override
    public boolean validate(FlowContext flowContext, TaskInfo taskInfo) {
        FlowNode currentNode = taskInfo.getNode();

        if(currentNode == null){
            return false;
        }

        //跳过开始和结束节点检查
        if(OperationType.START==currentNode.getOperationType() || OperationType.END == currentNode.getOperationType()){
            return true;
        }

        //校验当前节点
        if(!flowContext.getFlowService().existCurrentNode(taskInfo.getDocId(), currentNode.getId())){
            return false;
        }

        //校验用户权限
        if(!flowContext.getFlowService().validateNodeAuthority(taskInfo)){
            return false;
        }


        return true;
    }
}
